package top.superflow.flow.config.parse.impl.dft

import top.superflow.core.pool.resource.imp.GlobalResourcePoolManager
import top.superflow.flow.config.ResourceConfig
import top.superflow.flow.config.metadata.MetadataRestrainFactory
import top.superflow.flow.config.parse.impl.ResourceConfigParser
import top.superflow.flow.runtime.resource.RuntimeResource

class DefaultDBConnectionResourceConfigParser extends ResourceConfigParser{


  protected def parse(resourceConfig : ResourceConfig) : RuntimeResource = {
    val extResource = new RuntimeResource

    val metadataRestrain = MetadataRestrainFactory.getInstance.getRestrain(resourceConfig)

    var metaData : Object = null
    if(metadataRestrain != null) {
      metaData = metadataRestrain.getMetadata(resourceConfig)
    }

    val resourcePoolConfig = resourceConfig.getResourcePoolConfig(metadataRestrain)

    val extResourcePool = GlobalResourcePoolManager.getInstance.getPool(resourcePoolConfig)

    extResource.initResourcePoll(extResourcePool)

    extResource
  }
}
